import requestData from '@/utils/request';
export default {
  namespaced: true,
  state: {
    addCommentRes: [], // 添加评论返回结果
    commentList: [], // 评论列表
    myCommentListInfo: {}, // 我的评论列表信息
  },
  actions: {
    async addComment ({commit}, payload) {
      const res = await requestData({
        url: '/comment/add',
        method: 'POST',
        data: payload,
      });
      commit('updateComment', { addCommentRes: res });
    },
    async getComment ({commit}, payload) {
      const [res, err] = await requestData({
        url: '/comment/getList',
        data: payload,
      });
      if (!err) {
        commit('updateComment', { commentList: res });
      }
    },
    async getMyComment ({commit}, payload) { // 获取我的评论
      const [res, err] = await requestData({
        url: '/comment/getMyComment',
        data: payload,
      });
      if (!err) {
        commit('updateComment', { myCommentListInfo: res });
      }
    }
  },
  mutations: {
    updateComment(state, payload) {
      Object.assign(state, payload);
    }
  }
  
}
